<%@ page contentType="text/html;charset=utf-8"%>
<%@ page language="java" import="java.io.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ntko office文档控件示例-ms office文档编辑</title>
<meta content="IE=9" http-equiv="X-UA-Compatible" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
<!--设置缓存-->
<meta http-equiv="cache-control" content="no-cache,must-revalidate">
<meta http-equiv="pragram" content="no-cache">
<meta http-equiv="expires" content="0">
<style type="text/css">
#officecontrol {height:94% ; width:100%; position:absolute;}
body {  margin:0px; padding:0px; overflow:hidden;}
   </style>
<script LANGUAGE="JavaScript">
var TANGER_OCX_OBJ;//控件对象
var IsFileOpened; //标记文档是否打开
var cutomtoolbar=false; //是否已定义工具栏
//初始化页面
function intializePage(fileUrl){
	TANGER_OCX_OBJ=document.getElementById("TANGER_OCX");	
	//---------以下是告知文档控件，增加对PDF文档类型的支持。
	//AddDocTypePlugin方法参数说明:第一个参数扩展名,第二个参数ProID,第三个参数版本号，第四个参数是pdf插件相对当前网页的URL，
	//第5个参数是文档类型标识,第6个参数是是否自动下载插件dll,当设定为自动下载时，会比较当前客户机安装的版本，如果比第3个参数
	//指定的版本低，或者客户机没有安装，会自动下载并注册插件dll。
	TANGER_OCX_OBJ.AddDocTypePlugin(".pdf", "PDF.NtkoDocument", "4.0.0.1", "OfficeControl/ntkooledocall.cab", 51, true);
	TANGER_OCX_OBJ.AddDocTypePlugin(".tif", "TIF.NtkoDocument", "4.0.0.1", "OfficeControl/ntkooledocall.cab", 52, true);
	TANGER_OCX_OBJ.AddDocTypePlugin(".tiff", "TIF.NtkoDocument", "4.0.0.1", "OfficeControl/ntkooledocall.cab", 52, true);
	TANGER_OCX_OBJ.SetIEProtectionMode(false);
	TANGER_OCX_OBJ.IsShowNetErrorMsg =false;
	TANGER_OCX_OBJ.IsShowFileErrorMsg =false;
	//TANGER_OCX_OBJ.AddDomainToTrustSiteWithReturn("192.168.31.242");
	TANGER_OCX_OBJ.IsUseControlAgent = true;
	//TANGER_OCX_OBJ.FileSave =false;
	try{
	TANGER_OCX_OBJ.BeginOpenFromURL("templateFile/newWordTemplate.doc",true,false,"word.document");//templateFile/newWordTemplate.doc
	}catch(e){}
	
	TANGER_OCX_OBJ.FILEPrint=false;
	//OpenOfficeFromServerDir();
}


//删除左右两端的空格
function trim(str){ 
 return str.replace(/(^\s*)|(\s*$)/g, "");
}
//从服务器磁盘目录打开文档
function OpenOfficeFromServerDir() {
	TANGER_OCX_OBJ.OpenFromURL("OpenFromServerDir.jsp?filename=C:\\Users\\w_weihf\\Desktop\\aa.docx");
	//TANGER_OCX_OBJ.OpenFromURL("OpenFromServerDir.jsp?filename=newWordTemplate.doc");
}
//从数据库打开文档
function OpenOfficeFromMysql(){
	TANGER_OCX_OBJ.OpenFromURL("OpenFromMysql.jsp?id=1");
}
//从服务器项目相对路径打开文档
function OpenOfficeFromServer() {
	TANGER_OCX_OBJ.OpenFromURL("templateFile/newWordTemplate.doc");
}
//从URL打开文档
function OpenOfficeFromURL() {
	TANGER_OCX_OBJ.OpenFromURL("http://localhost:8080/ntkodemo2/templateFile/newWordTemplate.doc");
}
//从本地打开文档
function OpenLocalFile(){
	TANGER_OCX_OBJ.ShowDialog(1);
}

//保存文档到服务器磁盘目录
function   SaveOfficeToServerDir2(){ 
	var filename="我的文档.doc";
     var a = TANGER_OCX_OBJ.SaveAsOtherFormatToURL(5,
		"SaveToServerDir.jsp?filename="+filename,//提交到的url地址
		"upLoadFile",//文件域的id，类似<input type=file name=upLoadFile 中的name
		"p1=a&p2=b&p3=c",          //与控件一起提交的参数如："p1=a&p2=b&p3=c"
		filename,    //上传文件的名称，类似<input type=file 的value
		0  ,   //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		true
		);
		if(browser=="IE"){
			//TANGER_OCX_OBJ.ShowTipMessage("提示",trim(a));
		}
		
      }   
//保存文档到服务器磁盘目录
function   SaveOfficeToServerDir(){ 
	var filename="我的文档.docx";
     var a = TANGER_OCX_OBJ.SaveToURL(
		"SaveToServerDir1.jsp",//提交到的url地址
		"upLoadFile",//文件域的id，类似<input type=file name=upLoadFile 中的name
		"p1=a&p2=b&p3=c",          //与控件一起提交的参数如："p1=a&p2=b&p3=c"
		filename,    //上传文件的名称，类似<input type=file 的value
		0  ,   //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		true
		);
		if(browser=="IE"){
			TANGER_OCX_OBJ.ShowTipMessage("提示",trim(a));
		}
      }   
//保存文档到数据库
function SaveOfficeToMysql(){
	var filename="20150408001.doc";
     var a = TANGER_OCX_OBJ.SaveToURL(
				"SaveToMysql.jsp?id="+"0",//提交到的url地址
				"upLoadFile",//文件域的id，类似<input type=file name=upLoadFile 中的name
		"",          //与控件一起提交的参数如："p1=a&p2=b&p3=c"
		"",    //上传文件的名称，类似<input type=file 的value
		0    //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		);
		if(browser=="IE"){
			TANGER_OCX_OBJ.ShowTipMessage("提示",trim(a));
		}
}
//保存文档为PDF到服务器
function SaveAsPdfToUrl(){
	if(!TANGER_OCX_OBJ.IsPDFCreatorInstalled()){
		TANGER_OCX_OBJ.ShowTipMessage("提示","请先安装PDFCreator！");
		return;
	}
	try{
		var filename="2.pdf";
		TANGER_OCX_OBJ.PublishAsPDFToURL("SaveToServerDir.jsp?filename="+filename,"upLoadFile");

	}catch(e){
		alert(e);
	}
}
//新建文档
function CreateNewOffice(ProgId){
	//Word文档：						"Word.Document"
	//PowerPoint幻灯片：				"PowerPoint.Show"
	//Excel工作表：					"Excel.Sheet"
	TANGER_OCX_OBJ.CreateNew(ProgId); 
	//TANGER_OCX_OBJ.OpenFromURL("templateFile/normal.doc");  //为了解决不同客户端的兼容性文件建议从服务器打开一个2003格式的文档
}

//从服务器项目相对目录打开PDF文档
function OpenPdfFromUrl(){
	TANGER_OCX_OBJ.OpenFromURL("templateFile/test.pdf");
}

//从ODBC数据源读取文档。
function OpenFromODBCds(){
	TANGER_OCX_OBJ.OpenFromODBCds("nssmysql","select officedate from officefile where id=1","root","root");
}
//将文档写入到ODBC数据源。
function SaveToODBCds(){
	//TANGER_OCX_OBJ.SaveToODBCds("nssmysql","insert into officefile (officedate) values (?) ","root","root");
	TANGER_OCX_OBJ.SaveToODBCds("nssmysql","update  officefile set officedate =? where id=1 ","root","root");
}
//设置书签的值
function SetBookMarkValue(){
	var myDate = new Date();
	TANGER_OCX_OBJ.SetBookmarkValue("wenhao","NTKO-2015001");
	TANGER_OCX_OBJ.SetBookmarkValue("biaoti","关于上海办事处成立的通知");
	TANGER_OCX_OBJ.SetBookmarkValue("luokuan","重庆XX科技有限公司");		
	TANGER_OCX_OBJ.SetBookmarkValue("riqi",myDate.getFullYear()+"-"+myDate.getMonth()+"-"+myDate.getDate());
}
//获取书签的值
function GetBookMarkValue(){
	var mybokmarks=TANGER_OCX_OBJ.ActiveDocument.BookMarks;
	var content="";
	
	for(var i=1;i<=mybokmarks.count;i++)
	{
		content+="书签名称："+mybokmarks.Item(i).Name+"---书签内容："+TANGER_OCX_OBJ.GetBookmarkValue(i)+"\r\n"; 
	}
	TANGER_OCX_OBJ.ShowTipMessage("提示",content);
}
//是否显示书签标记
function IsShowBookMark() {
	TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.ActivePane.View.ShowBookmarks=!TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.ActivePane.View.ShowBookmarks;
}
//电子印章EKEY盖章
function AddEkeySecSign(){
	var uName="NTKO";
	if(IsFileOpened)
	{
		if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)
		{
			try
			{
				var doc = TANGER_OCX_OBJ.ActiveDocument;			
				var sel = doc.Application.Selection;	
				if(!doc.Bookmarks.Exists("luokuan"))
				{
					alert("盖章位置不存在，用印操作失败！");
					return;
				}						
				//获取盖章书签的起始位置
				sel.Goto(-1,0,0,"luokuan");
				var bke = sel.Range.End;
				var bks = sel.Range.Start;
				//获取书签的横向中心位置，并计算出像素值
				var cen = (bke-bks) / 2 + bks;
				sel.SetRange(cen,cen);				
				//设置印章偏移值
				var mLeft = -45;
				var mTop = -45;
				//从EKEY盖章
				TANGER_OCX_OBJ.AddSecSignFromEkey(uName, mLeft, mTop, 1, 2, false, true, true, false,"11111111",-1,false,false);					
			}
			catch(error){}
		}
		else
		{TANGER_OCX_OBJ.ShowTipMessage("提示","不能在该类型文档中使用安全签名印章.");}
	}
}
//电子印章键盘批注
function AddSecKeyBoardComment(){
	if(IsFileOpened)
	{
		if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)
		{
			try
			{
				TANGER_OCX_OBJ.AddSecKeyBoardComment("签章用户",0,0,1,2,false,false,true,false,"11111111",false);
			}
			catch(error){}
		}
		else
		{TANGER_OCX_OBJ.ShowTipMessage("提示","不能在该类型文档中使用安全签名印章.");}
	}
	
}
//文档禁止编辑
function SetDocReadOnly(){

	try{
	if(TANGER_OCX_OBJ.DocType==1){
		TANGER_OCX_OBJ.ActiveDocument.Protect(1,true,"ntko123");
	}else if(TANGER_OCX_OBJ.DocType==2){
		TANGER_OCX_OBJ.ActiveDocument.Protect("ntko123");
		for(var i=1;i<=TANGER_OCX_OBJ.ActiveDocument.Sheets.Count;i++)
		{
			TANGER_OCX_OBJ.ActiveDocument.Sheets(i).Protect("ntko123",true,true,true,true);
			//TANGER_OCX_OBJ.ActiveDocument.Sheets(i).EnableSelection =-4142;
		}
	}else{
		TANGER_OCX_OBJ.ShowTipMessage("提示","不允许设置只读.");
		
	}
	}catch(err)
	{
		alert("错误"+err.description);
	}
}
//文档允许编辑
function UnSetReadOnly(){
	if(TANGER_OCX_OBJ.DocType==1){
		TANGER_OCX_OBJ.ActiveDocument.UnProtect("ntko123");
	}else if(TANGER_OCX_OBJ.DocType==2){
		for(var i=1;i<=TANGER_OCX_OBJ.ActiveDocument.Sheets.Count;i++)
		{
			TANGER_OCX_OBJ.ActiveDocument.Sheets(i).Unprotect("ntko123");
		}
		
		TANGER_OCX_OBJ.ActiveDocument.application.ActiveWorkbook.Unprotect("ntko123");
	}else{
		TANGER_OCX_OBJ.ShowTipMessage("提示","不允许设置允许编辑.");
	}
}
//演示通过印章接口控制印章
function SetSignprintMode() {
	if(IsFileOpened)
	{
		if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)
		{			
			var ntkoocx = TANGER_OCX_OBJ;
			var mydoc = ntkoocx.ActiveDocument;
			var Shapes = mydoc.Shapes;
			var con = 0;
			for (var i = 1; i <= Shapes.Count; i++) {
				var curShape = Shapes(i);
				if ((12 == curShape.TYPE) && ("NTKO.SecSignControl".toUpperCase() == curShape.OLEFormat.ClassType.toUpperCase()))
				{
					var ntkoSignObj = curShape.OLEFormat.Object;   //得到印章对象
					ntkoSignObj.SetForceShowGray(true);				//使用印章的方法-强制变灰
					ntkoSignObj.RefreshCheckStatus();				//使用印章的方法-刷新印章状态
					ntkoSignObj.SetprintMode(1);					//使用印章的方法-设置打印属性
				}
			}
		}
		else
		{
			TANGER_OCX_OBJ.ShowTipMessage("提示","没有文档处于编辑状态或不是支持的签章文档类型！");
		}
	} 
}
//是否显示工具栏等
function IsShowToolBar(){
	TANGER_OCX_OBJ.Toolbars=!TANGER_OCX_OBJ.Toolbars;
	TANGER_OCX_OBJ.Titlebar=!TANGER_OCX_OBJ.Titlebar;
	TANGER_OCX_OBJ.Statusbar=!TANGER_OCX_OBJ.Statusbar;
	TANGER_OCX_OBJ.Menubar=!TANGER_OCX_OBJ.Menubar;
	TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.DocumentMap = !TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.DocumentMap  ;//隐藏导航窗格 
	TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.ActivePane.DisplayRulers=!TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.ActivePane.DisplayRulers;  //隐藏标尺
	TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.DocumentMap=false;//隐藏左侧导航格
}
//菜单栏项灰色
function MenubarShowGray() {
	TANGER_OCX_OBJ.FileOpen = !TANGER_OCX_OBJ.FileOpen;
	TANGER_OCX_OBJ.FileClose = !TANGER_OCX_OBJ.FileClose;		
	TANGER_OCX_OBJ.FilePageSetup = !TANGER_OCX_OBJ.FilePageSetup;	
	TANGER_OCX_OBJ.FilePrint = !TANGER_OCX_OBJ.FilePrint;
	TANGER_OCX_OBJ.FilePrintPreview = !TANGER_OCX_OBJ.FilePrintPreview;
}
//自定义工具栏功能
function ShowCutomToolBar(bool){
	if(bool){
		if(!cutomtoolbar)
		{
			TANGER_OCX_OBJ.CustomToolBar=true;
			TANGER_OCX_OBJ.AddCustomToolButton("打印", 9); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("打印预览", 10); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("关闭预览", 10); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("关闭文档", -1); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("功能区", -1); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("阅读模式", -1); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("菜单栏项灰色", -1); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("禁止编辑", -1); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("允许编辑", -1); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("接受痕迹-清稿", -1); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("拒绝痕迹-清稿", -1); //添加自定义工具栏按钮
			TANGER_OCX_OBJ.AddCustomToolButton("模板套红", -1); //添加自定义工具栏按钮
			
			cutomtoolbar=true;
		}
	}
	else
	{
		TANGER_OCX_OBJ.CustomToolBar=false;
	}
}
//痕迹保留
function SetReviewMode(flag){
	//TANGER_OCX_OBJ.ActiveDocument.TrackRevisions=flag;  //是否启动痕迹保留
	//TANGER_OCX_OBJ.ActiveDocument.ShowRevisions=flag;    //是否显示痕迹
	TANGER_OCX_OBJ.EnterRevisionMode(true,"111");
}
//接受或者取消所有修订
function TANGER_OCX_AllRevisions(flag)
{
	if(flag){
		TANGER_OCX_OBJ.ActiveDocument.AcceptAllRevisions();//接受所有的痕迹修订
	}else{
		TANGER_OCX_OBJ.ActiveDocument.Application.WordBasic.RejectAllChangesInDoc(); //拒绝所有痕迹修订
	}
}
//文件头套红
function insertRedHeadFromUrl(headFileURL)
{
	TANGER_OCX_OBJ.AddTemplateFromURL(headFileURL);
}
//word内容复制到textarea
function copyWordTextTOTextArea(){
	var content=getPContent();
	document.getElementById("FileText").innerText=content;
}
//获取全文内容
function getPContent(){
	//定义变量，存放内容 
	var content = ""; 
	//得到信息的段落数 
	var curSel = TANGER_OCX_OBJ.ActiveDocument.Application.Selection; 
	curSel.WholeStory();//选中全文 
	content = curSel.Range.Text; 
	return content;
} 
//保护文档部分修改 
function protectPartDoc(){
var marks=TANGER_OCX_OBJ.ActiveDocument.Bookmarks;//获取所有的书签
for(var i=1; i<=marks.Count; i++){
	if(marks(i).Name!="biaoti"){
	//var doc=TANGER_OCX_OBJ.Activedocument;
	//var start=doc.Bookmarks(marks(i).Name).range.start;
	//var end=doc.Bookmarks(marks(i).Name).range.end-1;
	//var ra=doc.range(start,end).Select();	
	TANGER_OCX_OBJ.ActiveDocument.Bookmarks(marks(i).Name).Range.Select();//选取书签区域保护
	TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Editors.Add(-1);//增加可编辑区域
	//NTKO START
	TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.View.ShadeEditableRanges = true;
	TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.View.ShowBookmarks = true;
	//NTKO END
} }
if(TANGER_OCX_OBJ.ActiveDocument.ProtectionType==-1){
	TANGER_OCX_OBJ.ActiveDocument.TrackRevisions=true;  //是否启动痕迹保留
	TANGER_OCX_OBJ.ActiveDocument.ShowRevisions=true;    //是否显示痕迹
	TANGER_OCX_OBJ.ActiveDocument.Protect(3,0,"232");//实现文档保护
}
}

function doProtect()
{
	var doc = TANGER_OCX_OBJ.ActiveDocument;
	var sel = doc.Application.Selection;
	var bks = doc.Bookmarks;
	var bksc = bks.Count;
	var sBegin = 0;
	var sEnd = 0;
	var docEnd = 0;
	var bkArray = new Array();
	var tmpBkArray = new Array();
	sel.Endkey(6);
	docEnd = sel.Start;
	
	//循环遍历书签
	for(var i=1;i<=bksc;i++)
	{
		//将书签起始位置存入数组
		bkArray[i] = bks(i).Range.Start+"."+bks(i).Range.End;
	} 

	//对书签起始位置数组进行排序
	bkArray.sort(
		function compare(a,b)
		{
			var at=a.split(".");
			var bt=b.split(".");
			if (parseInt(at[i])<parseInt(bt[i]))
			{
				return b-a;
			}
			else
			{
				return a-b;
			}
		}
	);

	//循环遍历书签起始位置数组
	for(var i=0;i<bkArray.length-1;i++)
	{
		tmpBkArray=bkArray[i].split(".");
		sEnd = tmpBkArray[0];
		sel.SetRange(sBegin,sEnd);
		sel.Editors.Add(-1);
		sBegin = tmpBkArray[1];
	} 		
	sel.SetRange(sBegin,docEnd);
	sel.Editors.Add(-1);			
	doc.Protect(3,0,"123");
	TANGER_OCX_OBJ.ActiveDocument.ActiveWindow.View.ShadeEditableRanges = false ;
}
//自定义工具栏操作
function CustomToolBarCom(btnIdx) {
	if (0 == btnIdx) {MyPrint(true);}
	if (1 == btnIdx) {MyPrintPreview();}
	if (2 == btnIdx) {MyExitPrintPreview();	}if (3 == btnIdx) {TANGER_OCX_OBJ.Close();}
	if (4 == btnIdx) {TANGER_OCX_OBJ.ToolBars = !TANGER_OCX_OBJ.ToolBars;}
	if (5 == btnIdx) {IsShowToolBar();}
	if (6 == btnIdx) {MenubarShowGray();}
	if (7 == btnIdx) {protectPartDoc();}
	if (8 == btnIdx) {UnSetReadOnly();}
	if (9 == btnIdx) {TANGER_OCX_AllRevisions(true);}
	if (10 == btnIdx) {TANGER_OCX_AllRevisions(false);}
	if (11 == btnIdx) {insertRedHeadFromUrl("templateFile/normal.doc");}
}
//打印文档
function MyPrint(selectprint){
	if(IsFileOpened){
		TANGER_OCX_OBJ.PrintOut(selectprint);
		alert(3);
		}
	else{TANGER_OCX_OBJ.ShowTipMessage("提示","无文档打开不能执行打印！");}
}
//打印预览文档
function MyPrintPreview(){
	if(IsFileOpened){TANGER_OCX_OBJ.PrintPreview();}
	else{TANGER_OCX_OBJ.ShowTipMessage("提示","无文档打开不能执行打印预览！");}
}
//退出打印预览文档
function MyExitPrintPreview(){
	TANGER_OCX_OBJ.ExitPrintPreview();
}
//增加自定义菜单
function MyCustomMenus() {
	var myobj = TANGER_OCX_OBJ;
	myobj.AddCustomMenu2(0, "新建文档");
	myobj.AddCustomMenu2(1, "打开文档");
	myobj.AddCustomMenu2(2, "保存文档");
	myobj.AddCustomMenu2(3, "书签管理");
	myobj.AddCustomMenu2(4, "电子印章");
	myobj.AddCustomMenu2(5, "文档信息");
	//增加一级菜单子菜单项目
	myobj.AddCustomMenuItem2(0, 0, -1, false, "新建WORD文档", false,4050);
	myobj.AddCustomMenuItem2(0, 1, -1, false, "新建EXCEL文档", false,4100);
	myobj.AddCustomMenuItem2(0, 2, -1, false, "新建PPT文档", false,4150);
	
	myobj.AddCustomMenuItem2(1, 0, -1, false, "从URL打开文档", false,5000);		
	myobj.AddCustomMenuItem2(1, 1, -1, false, "从服务器相对目录打开", false,5050);		
	myobj.AddCustomMenuItem2(1, 2, -1, false, "从服务器磁盘目录打开", false,5100);
	myobj.AddCustomMenuItem2(1, 3, -1, false, "从服务器打开PDF文档", false,5150);
	myobj.AddCustomMenuItem2(1, 4, -1, false, "跨服务器打开文档", false,5200);
	myobj.AddCustomMenuItem2(1, 5, -1, false, "从数据库打开office文档", false,5250);
	myobj.AddCustomMenuItem2(1, 6, -1, false, "从ODBC数据源读取文档", false,5300);
	
	myobj.AddCustomMenuItem2(2, 0, -1, false, "保存到服务器磁盘目录", false,6050);		
	myobj.AddCustomMenuItem2(2, 1, -1, false, "保存到数据库", false,6100);
	myobj.AddCustomMenuItem2(2, 2, -1, false, "跨服务器保存", false,6150);
	myobj.AddCustomMenuItem2(2, 3, -1, false, "保存ODBC", false,6200);
	myobj.AddCustomMenuItem2(2, 4, -1, false, "保存为PDF", false,6250);
	
	myobj.AddCustomMenuItem2(3, 0, -1, false, "设置书签", false,7050);
	myobj.AddCustomMenuItem2(3, 1, -1, false, "读取书签", false,7100);
	myobj.AddCustomMenuItem2(3, 2, -1, false, "是否显示标记", false,7150);
		
	myobj.AddCustomMenuItem2(4, 0, -1, false, "EKEY盖章光标定位", false,8050);
	myobj.AddCustomMenuItem2(4, 1, -1, false, "键盘批注", false,8100);
	myobj.AddCustomMenuItem2(4, 2, -1, false, "通过印章接口控制印章演示", false,8150);
	
	//增加二级菜单子菜单项目
	myobj.AddCustomMenuItem2(5, 0, 0, true, "WORD文档");
	myobj.AddCustomMenuItem2(5, 0, 0, false, "字数统计",false,9050);
	myobj.AddCustomMenuItem2(5, 0, 1, false, "文件大小", false,9100);
	myobj.AddCustomMenuItem2(5, 0, 2, false, "光标位置信息", false,9150);
	
	
}
//自定义菜单触发
function CustomMenuCmd(menuPos,submenuPos,subsubmenuPos,menuCaption,menuID){
	if (menuID==4050) {CreateNewOffice("Word.Document");}
	else if (menuID==4100) {CreateNewOffice("Excel.Sheet");}
	else if (menuID==4150) {CreateNewOffice("PowerPoint.Show");}
	else if (menuID==5000) {OpenOfficeFromURL();}
	else if (menuID==5050) {OpenOfficeFromServer();}
	else if (menuID==5100) {OpenOfficeFromServerDir();}
	else if (menuID==5150) {OpenPdfFromURL();}
	else if (menuID==5200) {TANGER_OCX_OBJ.ShowTipMessage("提示","跨服务器打开请联系QQ：2830194498");}
	else if (menuID==5250) {TANGER_OCX_OBJ.ShowTipMessage("提示","从数据库打开请联系QQ：2830194498");}
	else if (menuID==5300) {TANGER_OCX_OBJ.ShowTipMessage("提示","从ODBC数据源读取文档请联系QQ：2830194498");}
	else if (menuID==6050) {SaveOfficeToServerDir();}
	else if (menuID==6100) {TANGER_OCX_OBJ.ShowTipMessage("提示","保存到数据库请联系QQ：2830194498");}
	else if (menuID==6150) {TANGER_OCX_OBJ.ShowTipMessage("提示","跨服务器保存请联系QQ：2830194498");}
	else if (menuID==6200) {TANGER_OCX_OBJ.ShowTipMessage("提示","保存到ODBC请联系QQ：2830194498");}
	else if (menuID==6250) {SaveAsPdfToUrl();}
	else if (menuID==7050) {SetBookMarkValue();}
	else if (menuID==7100) {GetBookMarkValue();}
	else if (menuID==7150) {IsShowBookMark();}
	else if (menuID==8050) {AddEkeySecSign();}
	else if (menuID==8100) {AddSecKeyBoardComment();}
	else if (menuID==8150) {SetSignprintMode();}
	else if (menuID==9050) {GetWordInfo(0);}
	else if (menuID==9100) {GetWordInfo(1);}
	else if (menuID==9150) {GetWordInfo(2);}
	else {TANGER_OCX_OBJ.ShowTipMessage("提示","第" + menuPos +","+ submenuPos +","+ subsubmenuPos +"个菜单项,menuID="+menuID+",菜单标题为\""+menuCaption+"\"的命令被执行.");}	
}
//获取word信息
function GetWordInfo(cmd){
	if(cmd==0&&TANGER_OCX_OBJ.DocType==1){TANGER_OCX_OBJ.ShowTipMessage("提示","文档中一共有 "+TANGER_OCX_OBJ.activedocument.Characters.Count+" 字数。");}
	else if(cmd==1){TANGER_OCX_OBJ.ShowTipMessage("提示","当前文档大小有："+TANGER_OCX_OBJ.DocSize / 1024 + "kb");}
	else if(cmd==2&&TANGER_OCX_OBJ.DocType==1){
		var curpage = TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Information(3);
		var pagenum = TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Information(4);
		TANGER_OCX_OBJ.ShowTipMessage("提示","当前是第 " + curpage + " 页,一共有 " + pagenum + " 页。\r\n光标所在行：" + TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Information(10));
		}
}
//获取文档名称
function GetFileName(filepath) {
    if (filepath != "") {
        var names = filepath.split("\\");
        return names[names.length - 1];
    }
}
function serchKeyWords(keys)
  {
	var sel=TANGER_OCX_OBJ.ActiveDocument.Application.Selection; 
	var pagenum=TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Information(3);
	sel.Find.ClearFormatting();
	with(sel.Find){
	   Text=keys;
	   Replacement.Text = "";
	   Forward = true; 
	   Wrap = 1; 
	   Format = false;
	   MatchCase = false;
	   MatchWholeWord = false;
	   MatchByte = true;
	   MatchAllWordForms = false;
	   MatchSoundsLike = false;
	   MatchAllWordForms = false;
	   while(Execute()){  
		var bke = sel.Range.End;
		var bks = sel.Range.Start;
		var cen = (bke-bks) / 2 + bks;
		sel.SetRange(cen,cen);	
		sel.InsertAfter(pagenum);
	}
  }
  TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Homekey(6);                 //回到文档首页
}

function AddAttachFile(){	
	TANGER_OCX_OBJ.DeleAllFileFromUploadFileAttachFileList(); //删除上次选择的文件 ，也可以不删根据流程需求
	//DeleFileFromUploadFileAttachFileList(ByVal FileName) 此方法可以删除指定的文件
	TANGER_OCX_OBJ.AddFileToUploadFileAttachFileList("attachFile[]",true,"*");
	var count=TANGER_OCX_OBJ.GetUploadFileAttachFileCount();
	var filepaths="";
	for(var i=1;i<=count;i++){
		filepaths+=TANGER_OCX_OBJ.GetUploadFileAttachItemFile(i)+";";
	}
	document.getElementById("FileUploadText").value =filepaths;
}
var date1;  //书签赋值开始
var date2;    //书签赋值结束
function testbookmarks(){
	date1=new Date();
	for(var i=0;i<1000;i++)
	{
		
		TANGER_OCX_OBJ.SetBookmarkValue("wenhao",i);
	}
	date2=new Date();
	document.getElementById('txt').value=date2.getTime()-date1.getTime() ;
}


	</script>
</head>
<body onload='intializePage();'  style=" margin-top: 0; margin-left: 0;">
  <form id="form1" enctype="multipart/form-data" style="padding:0px;margin:0px;">
<input type="text" id="FileUploadText" name="FileUploadText" style="width:500px;" >
<input type="button" id="FileUpload" value="选择附件上传" onclick="AddAttachFile()"></input>
<input type="button" value="测试书签" onclick="testbookmarks()"> <input type="text" id="txt">
<div  id="officecontrol" class="officecontrol" > 
	<script language="javascript" type="text/javascript" src="OfficeControl/ntkoofficecontrol.js"></script>
</div>
</form>
<!--文档打开后触发事件-->
<script language="JScript" for="TANGER_OCX"  event="OnDocumentOpened(str,obj)">

OnComplete3(str,obj);
//SetReviewMode(true);
</script>

<!--自定义工具栏按钮触发事件-->
<script language="javascript" for="TANGER_OCX" event="OnCustomToolBarCommand(btnIdx)">
	CustomToolBarCom(btnIdx);
</script>
<script language="javascript" for="TANGER_OCX" event="OnDocActivated(IsActivated)">

</script>
<script language="javascript" for="TANGER_OCX" event="OnSaveToURL(type,code,html)">
alert(message);
</script>
<!--自定义菜单栏触发事件-->
<script language="JScript" for="TANGER_OCX" event="OnCustomMenuCmd2(menuPos,submenuPos,subsubmenuPos,menuCaption,menuID)">
CustomMenuCmd(menuPos,submenuPos,subsubmenuPos,menuCaption,menuID);
</script>
<!--自定义全屏触发事件-->
<script language="javascript" for="TANGER_OCX" event="OnScreenModeChanged(IsFullScreenMode)">

</script>
<!--自定义文件菜单触发事件-->
<script language="javascript" for="TANGER_OCX" event="OnFileCommand(Item, IsCancel)">
FileCommand(Item, IsCancel);
</script>
<!--自定义文件菜单触发事件-->
<script language="javascript" for="TANGER_OCX" event="OnWordBeforeRightClick(Item, IsCancel)">
//WordBeforeRightClick(Item, IsCancel);
</script>
<!--自定义word光标改变单触发事件-->
<script language="javascript" for="TANGER_OCX" event="OnWordWPSSelChange(Selection)">
//TANGER_OCX_OBJ.ActiveDocument.Application.WordBasic.EditOfficeClipboard();
	if(Selection.start!=Selection.end){
		//Selection.MoveRight ();
	}
</script>
<!--自定义EXCEL光标改变单触发事件-->
<script language="javascript" for="TANGER_OCX" event="OnSheetSelectionChange(SheetName, row, col)">
if(TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Rows.Count>1 || TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Columns.Count>1){
	//TANGER_OCX_OBJ.ActiveDocument.Application.Cells(row,col).Select();
}
if(TANGER_OCX_OBJ.ActiveDocument.Application.Selection.Areas.Count>1){
	//TANGER_OCX_OBJ.ActiveDocument.Application.Cells(row,col).Select();
}
//TANGER_OCX_OBJ.ActiveDocument.Application.SendKeys("{F2}") ;
//TANGER_OCX_OBJ.ActiveDocument.Application.Application.CutCopyMode=false;
//TANGER_OCX_OBJ.ActiveDocument.Application.Cells(65536,256).copy();
//test();
</script>
<!--自定义EXCEL双击触发事件-->
<script language="javascript" for="TANGER_OCX" event="OnSheetBeforeDoubleClick(SheetName, row, col, IsCancel)">
//alert("OnSheetBeforeDoubleClick"+row);
</script>
<!--自定义EXCEL单元格改变触发事件-->
<script language="javascript" for="TANGER_OCX" event="OnSheetChange(SheetName, row, col)">
//alert("gaib");
</script>
<script language="JScript" for="TANGER_OCX" event=" OnClickCustomContextMenu(MenuIndex)">
ClickCustomContextMenu(MenuIndex);
</script>
<script language="JScript" for="TANGER_OCX" event=" OnCustomButtonOnMenuCmd(btnPos, btnCaption, btnID)">
CustomButtonOnMenuCmd(MenuIndex);
</script>
<script language="JScript" for="TANGER_OCX" event=" OnAddTemplateFromURL(lFuncType, lStatCode, bstrRetData)">

</script>

</body>
</html>
